

#ifndef SCBEDITOR_H
#define SCBEDITOR_H

#include <wx/hashmap.h>
#include <wx/datetime.h>
#include <wx/fontmap.h>
#include <wx/timer.h>

#include "settings.h"
#include "seditorbase.h"
#include "printing_types.h"

extern const wxString g_EditorModified;


struct ScbEditorInternalData;
class ScbEditor;
class ProjectFile;
class SEditorColourSet;
class wxSplitterWindow;
class LoaderBase;
class cbStyledTextCtrl;
class wxScintillaEvent;
class wxBoxSizer;




class ScbEditor : public SEditorBase
{
        DECLARE_EVENT_TABLE()
        friend class SEditorManager;

    protected:

        ScbEditor(wxWindow* parent, const wxString& filename, SEditorColourSet* theme = 0L);
        ScbEditor(wxWindow* parent, LoaderBase* fileLdr, const wxString& filename, SEditorColourSet* theme = 0L);

        ScbEditor(const ScbEditor& rhs) : SEditorBase(rhs) { cbThrow(_T("Can't call ScbEditor's copy ctor!!!")); }

        ~ScbEditor();
    public:
        enum SplitType
        {
            stNoSplit = 0,
            stHorizontal,
            stVertical
        };


        virtual void operator=(const ScbEditor& rhs){ cbThrow(_T("Can't assign an ScbEditor* !!!")); }



        cbStyledTextCtrl* GetControl() const;


        cbStyledTextCtrl* GetLeftSplitViewControl() const { return m_pControl; }


        cbStyledTextCtrl* GetRightSplitViewControl() const { return m_pControl2; }


        SplitType GetSplitType() const { return m_SplitType; }


        bool IsOK() const { return m_IsOK; }


        void SetEditorTitle(const wxString& title);


        bool GetModified() const;


        void SetModified(bool modified = true);


        void SetProjectFile(ProjectFile* project_file,bool preserve_modified = false);


        ProjectFile* GetProjectFile() const { return m_pProjectFile; }


        void UpdateProjectFile();


        bool Save();


        bool SaveAs();


        bool SaveFoldState();


        bool FixFoldState();


        void FoldAll();


        void UnfoldAll();


        void ToggleAllFolds();


        void SetFoldingIndicator(int id);


        void FoldBlockFromLine(int line = -1);


        void UnfoldBlockFromLine(int line = -1);


        void ToggleFoldBlockFromLine(int line = -1);


        void SetColourSet(SEditorColourSet* theme);


        SEditorColourSet* GetColourSet() const { return m_pTheme; }


        void GotoMatchingBrace();


        void HighlightBraces();


        int GetLineIndentInSpaces(int line = -1) const;


        wxString GetLineIndentString(int line = -1) const;


        wxDateTime GetLastModificationTime() const { return m_LastModified; }


        void Touch();


        bool Reload(bool detectEncoding = true);


        void Print(bool selectionOnly, PrintColourMode pcm, bool line_numbers);


        void AutoComplete();


        void GotoLine(int line, bool centerOnScreen = true);


        bool AddBreakpoint(int line = -1, bool notifyDebugger = true);


        bool RemoveBreakpoint(int line = -1, bool notifyDebugger = true);


        void ToggleBreakpoint(int line = -1, bool notifyDebugger = true);


        bool HasBreakpoint(int line) const;


        void GotoNextBreakpoint();


        void GotoPreviousBreakpoint();


        void ToggleBookmark(int line = -1);


        bool HasBookmark(int line) const;


        void GotoNextBookmark();


        void GotoPreviousBookmark();


        void SetDebugLine(int line);


        void SetErrorLine(int line);


        void Split(SplitType split);


        void Unsplit();



        void Undo();
        void Redo();
        void Cut();
        void Copy();
        void Paste();
        bool CanUndo() const;
        bool CanRedo() const;
        bool HasSelection() const;
        bool CanPaste() const;
        bool IsReadOnly() const;


        void DoIndent();
        void DoUnIndent();

        virtual wxMenu* CreateContextSubMenu(long id);
        virtual void AddToContextMenu(wxMenu* popup,ModuleType type,bool pluginsdone);
        HighlightLanguage GetLanguage( ) const { return m_lang; }
        void SetLanguage( HighlightLanguage lang = HL_AUTO );

        wxFontEncoding GetEncoding( ) const;
        wxString GetEncodingName( ) const;
        void SetEncoding( wxFontEncoding encoding );

        bool GetUseBom() const;
        void SetUseBom( bool bom );


        static void ApplyStyles(cbStyledTextCtrl* control);
    private:

        bool LineHasMarker(int marker, int line = -1) const;
        void MarkerToggle(int marker, int line = -1);
        void MarkerNext(int marker);
        void MarkerPrevious(int marker);
        void MarkLine(int marker, int line);

        void DoFoldAll(int fold);
        void DoFoldBlockFromLine(int line, int fold);
        bool DoFoldLine(int line, int fold);
        void SetMarkerStyle(int marker, int markerType, wxColor fore, wxColor back);
        void UnderlineFoldedLines(bool underline);
        cbStyledTextCtrl* CreateEditor();
        void SetEditorStyle();
        void SetEditorStyleBeforeFileOpen();
        void SetEditorStyleAfterFileOpen();
        static void InternalSetEditorStyleBeforeFileOpen(cbStyledTextCtrl* control);
        static void InternalSetEditorStyleAfterFileOpen(cbStyledTextCtrl* control);
        void DetectEncoding();
        bool Open(bool detectEncoding = true);
        void DoAskForCodeCompletion();
        static wxColour GetOptionColour(const wxString& option, const wxColour _default);
        void NotifyPlugins(wxEventType type, int intArg = 0, const wxString& strArg = wxEmptyString, int xArg = 0, int yArg = 0);


        void OnMarginClick(wxScintillaEvent& event);
        void OnEditorUpdateUI(wxScintillaEvent& event);
        void OnEditorChange(wxScintillaEvent& event);
        void OnEditorCharAdded(wxScintillaEvent& event);
        void OnEditorDwellStart(wxScintillaEvent& event);
        void OnEditorDwellEnd(wxScintillaEvent& event);
        void OnEditorModified(wxScintillaEvent& event);
        void OnUserListSelection(wxScintillaEvent& event);
        void OnZoom(wxScintillaEvent& event);
        void OnScintillaEvent(wxScintillaEvent& event);
        void OnClose(wxCloseEvent& event);


        void OnContextMenuEntry(wxCommandEvent& event);
        bool OnBeforeBuildContextMenu(const wxPoint& position, ModuleType type);
        void OnAfterBuildContextMenu(ModuleType type);
        void DestroySplitView();

        void DoInitializations(const wxString& filename, LoaderBase* fileLdr = 0);


        bool m_IsOK;
        wxSplitterWindow* m_pSplitter;
        wxBoxSizer* m_pSizer;
        cbStyledTextCtrl* m_pControl;
        cbStyledTextCtrl* m_pControl2;
        cbStyledTextCtrl* m_foldBackup;
        SplitType m_SplitType;
        int m_ID;
        bool m_Modified;
        int m_Index;
        wxTimer m_timerWait;
        ProjectFile* m_pProjectFile;
        SEditorColourSet* m_pTheme;
        HighlightLanguage m_lang;
        wxDateTime m_LastModified;


        friend struct ScbEditorInternalData;
        ScbEditorInternalData* m_pData;
};

#endif
